package cn.doitedu.data_mock;

import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.RandomUtils;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Table;
import org.apache.hadoop.hbase.util.Bytes;
import org.junit.Test;

import java.io.IOException;
import java.util.Arrays;

public class HbaseDataGenerator {
    public static void main(String[] args) throws IOException {

        Configuration conf = HBaseConfiguration.create();
        conf.set("hbase.zookeeper.quorum","doitedu:2181");

        Connection connection = ConnectionFactory.createConnection(conf);
        Table table = connection.getTable(TableName.valueOf("user_profile_tags"));

        Put put1 = new Put(Bytes.toBytes(1L));
        put1.addColumn(Bytes.toBytes("f"),Bytes.toBytes("gender"),Bytes.toBytes("male"));
        put1.addColumn(Bytes.toBytes("f"),Bytes.toBytes("age"),Bytes.toBytes("25"));

        Put put2 = new Put(Bytes.toBytes(2L));
        put2.addColumn(Bytes.toBytes("f"),Bytes.toBytes("gender"),Bytes.toBytes("female"));
        put2.addColumn(Bytes.toBytes("f"),Bytes.toBytes("age"),Bytes.toBytes("24"));


        Put put3 = new Put(Bytes.toBytes(3L));
        put3.addColumn(Bytes.toBytes("f"),Bytes.toBytes("gender"),Bytes.toBytes("male"));
        put3.addColumn(Bytes.toBytes("f"),Bytes.toBytes("age"),Bytes.toBytes("18"));



        table.put(Arrays.asList(put1,put2,put3));


        table.close();
    }


    @Test
    public void genVideoInfo() throws IOException {

        Configuration conf = HBaseConfiguration.create();
        conf.set("hbase.zookeeper.quorum","doitedu:2181");

        Connection connection = ConnectionFactory.createConnection(conf);
        Table table = connection.getTable(TableName.valueOf("dim_cms_video"));

        for(long i=7;i<=100;i++) {
            Put put1 = new Put(Bytes.toBytes(i));
            put1.addColumn(Bytes.toBytes("f"), Bytes.toBytes("video_name"), Bytes.toBytes(RandomStringUtils.randomAlphabetic(5,10)));
            put1.addColumn(Bytes.toBytes("f"), Bytes.toBytes("video_type"), Bytes.toBytes(RandomStringUtils.randomAlphabetic(2)));
            put1.addColumn(Bytes.toBytes("f"), Bytes.toBytes("video_album"), Bytes.toBytes(RandomStringUtils.randomAlphabetic(2)));
            put1.addColumn(Bytes.toBytes("f"), Bytes.toBytes("video_author"), Bytes.toBytes(RandomStringUtils.randomAlphabetic(2)));
            put1.addColumn(Bytes.toBytes("f"), Bytes.toBytes("video_timelong"), Bytes.toBytes(RandomUtils.nextLong(1000,20000)));


            table.put(put1);

        }
        table.close();
    }

}
